import request from "@/utils/request";
import { CategoryList } from "./model/categoryModel";

enum api {
  getCategory1List = "/admin/product/getCategory1",
  getCategory2List = "/admin/product/getCategory2",
  getCategory3List = "/admin/product/getCategory3",
  deleteCategory1 = "/admin/product/removeCategory1",
  deleteCategory2 = "/admin/product/removeCategory2",
  deleteCategory3 = "/admin/product/removeCategory3",
  addCategory1 = "/admin/product/saveCategory1",
  addCategory2 = "/admin/product/saveCategory2",
  addCategory3 = "/admin/product/saveCategory3",
  updateCategory1 = "/admin/product/updateeCategory1",
  updateCategory2 = "/admin/product/updateeCategory2",
  updateCategory3 = "/admin/product/updateeCategory3",
}
export const updateCategory1Api = (name: string) => {
  return request.put(api.updateCategory1, { name });
};
// {
//   "id": 0,
//   "name": "string"
// }

// {
//   "category1Id": 0,
//   "id": 0,
//   "name": "string"
// }

// {
//   "category2Id": 0,
//   "id": 0,
//   "name": "string"
// }
/**
 * 添加三级分类
 * @param category2Id 二级分类id
 * @param name 三级分类名称
 * @returns null
 */
export const addCategory3Api = (category2Id: number, name: string) => {
  return request.post<any, null>(api.addCategory3, {
    name,
    category2Id,
  });
};
/**
 * 添加二级分类
 * @param category1Id 一级分类id
 * @param name 二级分类名称
 * @returns null
 */
export const addCategory2Api = (category1Id: number, name: string) => {
  return request.post<any, null>(api.addCategory2, {
    name,
    category1Id,
  });
};
/**
 * 添加一级分类
 * @param name 一级分类名称
 * @returns null
 */
export const addCategory1Api = (name: string) => {
  return request.post<any, null>(api.addCategory1, { name });
};

/**
 * 删除一级分类
 * @param id
 * @returns null
 */
export const deleteCategory1Api = (id: number) => {
  return request.delete<any, null>(api.deleteCategory1 + `/${id}`);
};
/**
 * 删除二级分类
 * @param id
 * @returns null
 */
export const deleteCategory2Api = (id: number) => {
  return request.delete<any, null>(api.deleteCategory2 + `/${id}`);
};
/**
 * 删除三级分类
 * @param id
 * @returns null
 */
export const deleteCategory3Api = (id: number) => {
  return request.delete<any, null>(api.deleteCategory3 + `/${id}`);
};
/**
 * 获得一级菜单的请求
 * @returns CategoryList
 */
export const getCategory1List = () => {
  return request.get<any, CategoryList>(api.getCategory1List);
};
/**
 * 获得二级菜单的请求
 * @param category1Id number
 * @returns CategoryList
 */
export const getCategory2List = (category1Id: number) => {
  return request.get<any, CategoryList>(
    api.getCategory2List + `/${category1Id}`
  );
};
/**
 * 获得三级菜单的请求
 * @param category2Id number
 * @returns CategoryList
 */
export const getCategory3List = (category2Id: number) => {
  return request.get<any, CategoryList>(
    api.getCategory3List + `/${category2Id}`
  );
};
